package com.dongdongshop.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbAreasMapper;
import com.dongdongshop.mapper.TbCitiesMapper;
import com.dongdongshop.mapper.TbProvincesMapper;
import com.dongdongshop.pojo.user.*;
import com.dongdongshop.service.user.AreasService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Service
@Component
public class AreasServiceImpl implements AreasService {

    //表 :省的mapper
    @Resource
    private TbProvincesMapper tbProvincesMapper;

    //表 :市的mapper
    @Resource
    private TbCitiesMapper tbCitiesMapper;

    //表 :县的mapper
    @Resource
    private TbAreasMapper tbAreasMapper;

    /*
    * 查询省的所有数据
    * */
    @Override
    public List<TbProvinces> getAddressList() {
        return tbProvincesMapper.selectByExample(new TbProvincesExample());
    }

    /*
    * 查询市
    * */
    @Override
    public List<TbCities> getCitiesList(String provinceid) {
        TbCitiesExample example = new TbCitiesExample();
        TbCitiesExample.Criteria criteria = example.createCriteria();
        criteria.andProvinceidEqualTo(provinceid);
        return tbCitiesMapper.selectByExample(example);
    }

    /*
    * 查询县
    * */
    @Override
    public List<TbAreas> getAreaList(String cityid) {
        TbAreasExample example = new TbAreasExample();
        TbAreasExample.Criteria criteria = example.createCriteria();
        criteria.andCityidEqualTo(cityid);
        return tbAreasMapper.selectByExample(example);
    }
}
